package screens;

import media.AudioManager;
import media.Musics;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Screen;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.g2d.TextureAtlas;
import com.badlogic.gdx.scenes.scene2d.Actor;
import com.badlogic.gdx.scenes.scene2d.Stage;
import com.badlogic.gdx.scenes.scene2d.ui.Skin;
import com.badlogic.gdx.scenes.scene2d.ui.Table;
import com.badlogic.gdx.scenes.scene2d.ui.TextButton;
import com.badlogic.gdx.scenes.scene2d.utils.ChangeListener;
import com.badlogic.gdx.scenes.scene2d.utils.ChangeListener.ChangeEvent;
import com.me.jnrgame.JnR;

public class StartGameScreen implements Screen{

	private JnR game;
	private Stage stage;
	private LevelScreen levelScreen;
	private Skin skin;
	
	public StartGameScreen(JnR _game) {
		super();
		game = _game;
		game.setStartGameScreen(this);
		stage = new Stage(game.getScreenWidth(), game.getScreenHeight(), true);
		TextureAtlas menuAtlas = new TextureAtlas(
				Gdx.files.internal("data/screen-layouts/mainmenu/uiskin.atlas"));
		Gdx.input.setInputProcessor(stage);
		skin = new Skin(
				Gdx.files.internal("data/screen-layouts/mainmenu/uiskin.json"),
				menuAtlas);
		Table table = new Table(skin);
		table.setWidth(stage.getWidth());
		table.setHeight(stage.getHeight());
		table.row();
		
		TextButton continueGameButton = new TextButton("Continue Game", skin);
		continueGameButton.addListener(new ChangeListener() {
			@Override
			public void changed(ChangeEvent event, Actor actor) {
				// TODO Auto-generated method stub
				game.setScreen(game.getLevelScreen());
				Gdx.input.setInputProcessor(game.getLevelScreen().getStage());
								AudioManager.playMusic(Musics.Level);
				
			}
		});
		table.add(continueGameButton).size(300f, 60f).uniform().spaceBottom(10);
		table.row();
		
		TextButton newGameButton = new TextButton("New Game", skin);
		newGameButton.addListener(new ChangeListener() {
			@Override
			public void changed(ChangeEvent event, Actor actor) {
				// TODO Auto-generated method stub
				levelScreen = new LevelScreen(2, game);
				game.setUpLevel(levelScreen);
				AudioManager.playMusic(Musics.Level);
			}
		});
		table.add(newGameButton).size(300f, 60f).uniform().spaceBottom(10);
		table.row();
		
		stage.addActor(table);
	}

	@Override
	public void render(float delta) {
		// TODO Auto-generated method stub
		Gdx.gl.glClearColor(0.2f, 0.2f, 0.2f, 1);
		Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);

		stage.act(Math.min(Gdx.graphics.getDeltaTime(), 1 / 30f));
		stage.draw();
	}

	@Override
	public void resize(int width, int height) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void show() {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void hide() {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void pause() {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void resume() {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void dispose() {
		// TODO Auto-generated method stub
		
	}
	public Stage getStage(){
		return stage;
	}
	
}
